/**
 * 定义字典方法,根据英文列名获取中文列名 has not test
 * 可以全部不传,这样你的数据中的就必须按照 engName chName这两个key来定义
 * @param formColDir 字典
 * example Array : [{engName:"user",chName:"用户"},{engName:"role",chName:"角色"},{engName:"authority",chName:"权限"}]
 *
 * @param dirEngName  default chName
 * @param dirChName  default engName
 *
 * @returns {Function}
 */
import el from 'element-ui/src/locale/lang/el'

export const getChNameByEngName = ({ colDir, dirEngName = 'engName', dirChName = 'chName', isShowWarn = true } = {}) => (engName) => {
  if (!colDir) {
    throw new Error(' dictionary 不存在! 请检查传入参数--- chino')
  }
  const matches = colDir.filter((e) => {
    return e[dirEngName] === engName
  })
  if (matches.length) {
    return matches[0][dirChName]
  }
  isShowWarn && console.warn(`转换列失败,列名 "${engName}" 不存在于字典!`)
  return engName
}

export const getChNameByEngNameChino = ({ isShowWarn = true, isRetOriginParamName = true, retDefault}) =>
  ({ colDir, paramName = 'engName', needName = 'chName' } = {}) => (engName) => {

    !colDir && console.warn(' dictionary 不存在! 请检查传入参数--- chino')
    const matched = colDir.find((e) => e[paramName] === engName)
    console.log(matched);
    if (matched) {
      return matched[needName]
    }
    isShowWarn && console.warn(`转换列失败,列名 "${engName}" 不存在于字典!`)
    if (isRetOriginParamName) {
      return engName
    }
    console.log(retDefault);
    return retDefault

  }
